/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tpc.client.systeme.xtend.datasource;

import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.types.FieldType;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.tpc.dao.core.Zipcode;

/**
 *
 * @author frederic.fortin
 */
public class ZipcodeDSFields {
    
    public ZipcodeDSFields() {
        
    }
    
    public DataSourceField[] setFields() {
        DataSourceField fldZipcodeId = new DataSourceField();
        fldZipcodeId.setName("zipcode_id");
        fldZipcodeId.setType(FieldType.INTEGER);
        fldZipcodeId.setPrimaryKey(Boolean.TRUE);
        fldZipcodeId.setHidden(Boolean.TRUE);
        
        DataSourceField fldZipcodeName = new DataSourceField();
        fldZipcodeName.setName("zipcode_name");
        fldZipcodeName.setType(FieldType.TEXT);
        fldZipcodeName.setPrimaryKey(Boolean.FALSE);
        fldZipcodeName.setHidden(Boolean.FALSE);
        
        DataSourceField fldCityId = new DataSourceField();
        fldCityId.setName("zipcode_city_id");
        fldCityId.setType(FieldType.INTEGER);
        fldCityId.setPrimaryKey(Boolean.FALSE);
        fldCityId.setHidden(Boolean.TRUE);
        
        DataSourceField fldCityName = new DataSourceField();
        fldCityName.setName("zipcode_city_name");
        fldCityName.setType(FieldType.TEXT);
        fldCityName.setPrimaryKey(Boolean.FALSE);
        fldCityName.setHidden(Boolean.FALSE);
        
        DataSourceField fldStateId = new DataSourceField();
        fldStateId.setName("zipcode_state_id");
        fldStateId.setType(FieldType.INTEGER);
        fldStateId.setPrimaryKey(Boolean.FALSE);
        fldStateId.setHidden(Boolean.TRUE);
        
        DataSourceField fldStateName = new DataSourceField();
        fldStateName.setName("zipcode_state_name");
        fldStateName.setType(FieldType.TEXT);
        fldStateName.setPrimaryKey(Boolean.FALSE);
        fldStateName.setHidden(Boolean.FALSE);
                
        DataSourceField fldCountryId = new DataSourceField();
        fldCountryId.setName("zipcode_country_id");
        fldCountryId.setType(FieldType.INTEGER);
        fldCountryId.setPrimaryKey(Boolean.FALSE);
        fldCountryId.setHidden(Boolean.TRUE);
        
        DataSourceField fldCountryName = new DataSourceField();
        fldCountryName.setName("zipcode_country_name");
        fldCountryName.setType(FieldType.TEXT);
        fldCountryName.setPrimaryKey(Boolean.FALSE);
        fldCountryName.setHidden(Boolean.FALSE);
                
        DataSourceField[] fields = {fldZipcodeId,fldZipcodeName,fldCityId,fldCityName,fldStateId,fldStateName,fldCountryId,fldCountryName};
        return fields;
    }
        
        public ListGridRecord[] setLGRecord(Zipcode[] result) {
            ListGridRecord[] zips = null;
            if (result != null) {
                    zips = new ListGridRecord[result.length];
                    for (int i = 0; i < result.length; i++) {
                        zips[i] = new ListGridRecord();
                        zips[i].setAttribute("zipcode_id", result[i].getId());
                        zips[i].setAttribute("zipcode_name", result[i].getName());
                        zips[i].setAttribute("zipcode_city_id", result[i].getCityId());
                        zips[i].setAttribute("zipcode_city_name", result[i].getCityName());
                        zips[i].setAttribute("zipcode_state_id", result[i].getStateId());
                        zips[i].setAttribute("zipcode_state_name", result[i].getStateName());
                        zips[i].setAttribute("zipcode_country_id", result[i].getCountryId());
                        zips[i].setAttribute("zipcode_country_name", result[i].getCountryName());
                    }
                }
            return zips;
        }
    
}
